<?php
/**
 *Database Class
 *Base Class for all class that need connect to the database
 *This versión is used to MySQL Server, this implement singlenton
 *Only one instace can to exist
 *@author Alberto Berroteran <ashrey10@yahoo.es>
 *@version 0.· Beta
 *@copyright Copyrigth (c)2008 Alberto Berroteran
 */
define('DB_MYSQL', 1);
define('DB_SQLITE', 2);
define('DB_PGSQL', 3);
class dbConnect{

	public $s_db = '';
	public $error = false;
	public $sError = 'No Error';

	private static $o_instance = null;
	private $i_type = null;
	private $o_driver = null;

	private function __construct($a_conf){
		extract($a_conf);
		$s_type = isset($type)? $type: DB_MYSQL;
		switch($s_type){
			case DB_MYSQL:
			$this->o_driver = new dbMysql($server, $user, $pass, $dbname);
			break;
		}
	}
	
	public function query($s_sql){
		return $this->o_driver->query($s_sql);
	}
	
	public function safe($s_str){
		return $this->o_driver->safe($s_str);
	}
	
	public function getFields($s_table){
		return $this->o_driver->getFields($s_table);
	}

	public static function getInstance($a_conf=array()){
		if(!self::$o_instance instanceof self){
			self::$o_instance = new dbConnect($a_conf);
		}
		return self::$o_instance;
	}

	public function __clone(){
		throw ABException('This class implements singlenton, It cannot to be cloned');
	}

	public function __wakeup(){
		throw ABException('This class implements singlenton, It cannot to be unserialized.');
	}

}
?>
